//
//  ETitleSelectPlaceView.m
//  Common
//
//  Created by shiqing guo on 2018/8/6.
//  Copyright © 2018年 www.bitkinetic.com. All rights reserved.
//

#import "ETitleSelectPlaceView.h"
#import "Macro.h"
#import "ECityPickView.h"
#import "UIView+DDAddition.h"

@interface ETitleSelectPlaceView () <UITextFieldDelegate>
@property (nonatomic, strong) UILabel *lblTitle;
@property (nonatomic, strong) UIButton *btnPlace;
@property (nonatomic, strong) UIImageView *igvIcon;
@end

@implementation ETitleSelectPlaceView

- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        self.frame = frame;
        [self addSubviews];
    }
    return self;
}

- (void)addSubviews
{
    [self addSubview:self.lblTitle];
    [self addSubview:self.btnPlace];
    [self addSubview:self.igvIcon];
}

- (void)layoutSubviews
{
    self.btnPlace.right = self.width;
    self.lblTitle.height = self.height;
    self.btnPlace.height = self.height;
    self.igvIcon.right = self.btnPlace.right;
    self.igvIcon.centerY = self.height/2;
}

- (void)setStrTitle:(NSString *)strTitle
{
    _strTitle = strTitle;
    self.lblTitle.text = strTitle;
    [self setNeedsLayout];
}

- (void)setStrPlaceholder:(NSString *)strPlaceholder
{
    _strPlaceholder = strPlaceholder;
    [self.btnPlace setTitle:strPlaceholder forState:UIControlStateNormal];
    [self setNeedsLayout];
}

- (void)setWidthOfTitle:(CGFloat)widthOfTitle
{
    _widthOfTitle = widthOfTitle;
    self.lblTitle.width = widthOfTitle;
    [self setNeedsLayout];
}

- (void)setWidthOfContent:(CGFloat)widthOfContent
{
    _widthOfContent = widthOfContent;
    self.btnPlace.width = widthOfContent;
    [self setNeedsLayout];
}

#pragma mark - 返回数据


#pragma mark - 懒加载
- (UILabel *)lblTitle
{
    if (!_lblTitle) {
        _lblTitle = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 1.0f, 1.0f)];
        _lblTitle.font = SystemFont(16.0f);
        _lblTitle.textColor = [EPColor epColor_TitleBlack];
    }
    return _lblTitle;
}


- (UIButton *)btnPlace
{
    if (!_btnPlace) {
        _btnPlace = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 1.0f, 1.0f)];
        [_btnPlace setTitleColor:[EPColor epColor_TitleBlack] forState:UIControlStateNormal];
        _btnPlace.titleLabel.font = SystemFont(16.0f);
        [_btnPlace addTarget:self action:@selector(btnPlaceClick:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _btnPlace;
}

- (UIImageView *)igvIcon
{
    if (!_igvIcon) {
        _igvIcon = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"trip_right_g"]];
    }
    return _igvIcon;
}


#pragma mark - UIButton Action
- (void)btnPlaceClick:(id)sender
{
    WEAKSELF
    [ECityPickView showCityPickerWithDefaultSelected:nil isAutoSelect:NO resultBlock:^(NSArray *selectCityArr, NSArray *indexArr) {

        NSDictionary *city = selectCityArr[1];
        weakSelf.strCity = [city objectForKey:@"name"];
        weakSelf.strCityCode = [city objectForKey:@"code"];
        [weakSelf.btnPlace setTitle:weakSelf.strCity forState:UIControlStateNormal];
    }];
}



@end
